﻿/*
 * @autor: hectorea
 * @date: 03/08/12
 * @project: SquareRoot
 * @Reference:
 *  http://en.wikipedia.org/wiki/Prime_number
 * 
 */

using System;

namespace PrimeNumbers
{
    internal static class IntExtension
    {
        /// <summary>
        /// Print the first n prime from 2 until int.MaxValue
        /// </summary>
        /// <param name="number">n number</param>
        internal static void PrimeNumbers(this int number)
        {
            if (number >= 2)
            {
                int count = 0;

                for (int i = 2; i < number; i++)
                {
                    for (int j = 1; j <= i; j++)
                    {
                        if (i % j == 0)
                        {
                            count++;

                            if (count > 2)
                                break;
                        }
                    }

                    if (count <= 2)
                        Console.Write(" {0} ", i);

                    count = 0;
                }
            }
            else
            {
                Console.WriteLine("The number must be 2 or greater");
            }
        }

        internal static bool IsPrimeNumber(this int number)
        {
            if (number == 0 || number == 1) return false;
            if(number == 2) return true;
            if(number%2==0) return false;

            for (int i = 3; i < number; i+=2)
			{
                if (number % i == 0) return false;	    
			}

            return true;
        }
    }



}